package com.leetcode.p0;

import com.bean.ListNode;
import com.utils.DataUtils;

public class Test82 {

    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummyNode = new ListNode(-2);
        dummyNode.next = head;
        ListNode curNode = dummyNode;

        boolean delete = false;

        while (curNode.next != null) {

            delete = false;
            while (curNode.next.next != null && curNode.next.val == curNode.next.next.val) {
                delete = true;
                curNode.next = curNode.next.next;
            }

            if (delete) {
                curNode.next = curNode.next.next;
            } else {
                curNode = curNode.next;
            }
        }

        return dummyNode.next;
    }

    public static void main(String[] args) {
        Test82 test = new Test82();
//        ListNode head = DataUtils.getListNode(new int[]{1, 1, 1, 2, 3, 3, 3, 4, 5, 6, 6});
        ListNode head = DataUtils.getListNode(new int[]{1, 3, 3, 4, 4});
        DataUtils.printListNode(test.deleteDuplicates(head));
    }
}
